//
//  YLCommonListItemCell.m
//  YLScaner
//
//  Created by Admin on 2025/9/25.
//

#import "YLCommonListItemCell.h"

@interface YLCommonListItemCell ()
/// 内容容器
@property (weak, nonatomic) IBOutlet UIView *bodyView;

/// 容器-最外部
@property (weak, nonatomic) IBOutlet UIStackView *mainStack;
/// 文字内容 + 辅助内容
@property (weak, nonatomic) IBOutlet UIStackView *groupStack;
/// 文字内容
@property (weak, nonatomic) IBOutlet UIStackView *textStack;
/// 辅助内容
@property (weak, nonatomic) IBOutlet UIStackView *assistStack;

// MARK: - 约束信息
/// 边距-内容左右
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bodyMarginL;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bodyMarginR;

/// 边距-主Stack
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainStackMarginR;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainStackMarginL;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainStackMarginT;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainStackMarginB;

/// 边距线
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineMarginR;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineMarginL;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineMarginB;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineHeight;

/// 图片尺寸
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *assistImageConstraint;


@end


@implementation YLCommonListItemCell

static NSString *reuseIdentifier = @"YLCommonListItemCell";

/// 快捷方法-注册
+ (void)registerWithTableView:(UITableView *)tableview{

    NSBundle *bundle = [NSBundle bundleForClass:YLCommonListItemCell.class];
    [tableview registerNib: [UINib nibWithNibName:@"YLCommonListItemCell" bundle:bundle] forCellReuseIdentifier:reuseIdentifier];
}

/// 快捷方法-初始化
+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
    
    return [tableView dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath];;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backgroundColor = UIColor.clearColor;
}


//MARK: - 属性设置
//MARK: - Stack间距属性
/// 文本视图、辅助视图间距
- (void)setSpaceGroupStack:(CGFloat)spaceGroupStack{
    
    self.groupStack.spacing = spaceGroupStack;
}
/// 文本视图间距
- (void)setSpaceTextStack:(CGFloat)spaceTextStack{
    
    self.textStack.spacing = spaceTextStack;
}
/// 辅助视图间距
- (void)setSpaceAssistStack:(CGFloat)spaceAssistStack{
    
    self.assistStack.spacing = spaceAssistStack;
}
/// 图标圆角
- (void)setIconRadius:(CGFloat)iconRadius{
    
    self.iconImage.layer.cornerRadius = iconRadius;
    self.iconImage.layer.masksToBounds = YES;
}
/// 辅助图片尺寸
- (void)setAssistImageH:(CGFloat)assistImageH{

    self.assistImageConstraint.constant = assistImageH;
}

//MARK: - mainStack属性
/// 边距属性有效值：左、右、下、上
- (void)setMainStackEdge:(UIEdgeInsets)mainStackEdge{
    
    self.mainStackMarginT.constant = mainStackEdge.top;
    self.mainStackMarginL.constant = mainStackEdge.left;
    self.mainStackMarginR.constant = mainStackEdge.right;
    self.mainStackMarginB.constant = mainStackEdge.bottom;
}
/// 间距
- (void)setMainStackSpace:(CGFloat)mainStackSpace{
    
    self.mainStack.spacing = mainStackSpace;
}

//MARK: - 容器属性
/// body左边距
- (void)setBodyLeft:(CGFloat)bodyLeft{
    
    self.bodyMarginL.constant = bodyLeft;
}
/// body右边距
- (void)setBodyRight:(CGFloat)bodyRight{
    
    self.bodyMarginR.constant = bodyRight;
}
/// body背景颜色
- (void)setBodyBackgroundColor:(UIColor *)bodyBackgroundColor{
    
    self.bodyView.backgroundColor = bodyBackgroundColor;
}

//MARK: - 下划线属性
/// 下划线高度
- (void)setLineH:(CGFloat)lineH{
 
    self.lineHeight.constant = lineH;
}
/// 下划线边距属性有效值：左、右、下
- (void)setLineEdge:(UIEdgeInsets)lineEdge{

   
    self.lineMarginL.constant = lineEdge.left;
    self.lineMarginR.constant = lineEdge.right;
    self.lineMarginB.constant = lineEdge.bottom;
}

//MARK: - 设置圆角
- (void)drawRect:(CGRect)rect{
    
    [super drawRect:rect];
    
    if (self.radius <= 0)
    {
        self.bodyView.layer.mask = nil;
    }else
    {
        // 1. 绘制指定角为圆角的路径
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bodyView.bounds
                                                       byRoundingCorners:self.corner
                                                             cornerRadii:CGSizeMake(self.radius, self.radius)];
        // 2. 创建遮罩层
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = self.bodyView.bounds;
        maskLayer.path = maskPath.CGPath; // 关联路径
        
        // 3. 设置遮罩（只显示路径内的区域）
        self.bodyView.layer.mask = maskLayer;
    }
}



@end
